<template>
  <div class="view">
    <Panel :title="title">                                                                                        
    <el-form label-position="top">
      <el-row :gutter="20">
        <el-col :span="18">
          <el-form-item label="课程名称" required>
            <el-input v-model="course.name" placeholder="课程名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="可见状态" required>
            <el-switch
            v-model="course.visible">
            </el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="课程简介" required>
            <Simditor v-model="course.description" />
           
          </el-form-item>
        </el-col>
                <el-col :span="24">
          <el-form-item label="教学目标" required>
            <Simditor v-model="course.goal" />
           
          </el-form-item>
        </el-col>
                <el-col :span="24">
          <el-form-item label="内容概览" required>
            <Simditor v-model="course.content" />
           
          </el-form-item>
        </el-col>
                <el-col :span="24">
          <el-form-item label="参考资源" required>
            <Simditor v-model="course.references" />
           
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <save @click.native="saveCourse"></save>
    </Panel>
  </div>
</template>

<script>

import api from '../../api.js'
// Simditor是写好的编辑栏组件，我们可以直接引入使用
import Simditor from '../../components/Simditor.vue'

export default {
  name: 'CreateCourse',
  components: { Simditor },
  data () {
    return {
      title: '添加课程',
      course: {
        name: '',
        description: '',
        goal: '',
        content: '',
        references: '',
        visible: false
      }
    }
  },
  mounted () {
    if (this.$route.name === 'edit-course') {
      this.title = '编辑课程'
      api.getCourse(this.$route.params.courseId).then(res => {
        this.course = res.data.data
      }).catch(() => {
      })
    }
  },
  methods: {
    saveCourse () {
      let funcName = this.$route.name === 'edit-course' ? 'editCourse' : 'createCourse'
      let data = Object.assign({}, this.course)
      console.log(data)
      // api[funcName](data).then(res => {
        // this.$router.push({name: 'course-list', query: {refresh: 'true'}})
      // }).catch((e) => {
      // })
    }
  }
}
</script>
